package model

import (
	"database/sql"
	"strings"
	"time"

	"gorm.io/gorm"

	"shorten/pkg/util"
)

// 基础用户表
type User struct {
	UserId    int `gorm:"primaryKey"`
	UserName  string
	Password  string
	Salt      string
	UserState int8
	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

func (u User) Create(db *gorm.DB) error {
	return db.Create(&u).Error
}

func (u User) FindByName(db *gorm.DB, userName string, column []string) *User {
	err := db.Model(&u).Select(strings.Join(column, ",")).Where("user_name=?", userName).Limit(1).Find(&u).Error
	util.CheckErr(err)
	return &u
}
